package org.jeecg.modules.controller;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.result.Result;
import org.jeecg.common.util.result.ResultMapper;
import org.springframework.cache.support.NullValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.weixin4j.model.menu.Menu;
import org.weixin4j.model.menu.SingleButton;
import org.weixin4j.model.menu.ViewButton;
import org.weixin4j.spring.WeixinTemplate;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStream;
import java.net.HttpURLConnection;

/**
 * @author guoyh
 * @ClassName MenuController
 * @Description
 * @since 2020/9/15 00:31
 **/
@Slf4j
@RestController
@RequestMapping("wx/menu")
public class MenuController {

    @Resource
    private WeixinTemplate weixinTemplate;

    @GetMapping("/init")
    public Result<NullValue> menu(@RequestParam("pwd") String pwd){
        if (!StringUtils.equals(pwd,"guoyh")){
            return ResultMapper.error();
        }

        try {
            //【菜单一】 我的医生
            ViewButton woDeYiSheng = new ViewButton("我的医生");
            woDeYiSheng.setUrl("https://weixin.dyzh120.com/xetstudio/doctors");

            //【菜单二】 大医智慧
            ViewButton daYiZhiHui = new ViewButton("大医智慧");
            daYiZhiHui.setUrl("https://appigc72vmw2720.h5.xiaoeknow.com");

            //【菜单三】 个人中心
            ViewButton geRenZhongXin = new ViewButton("个人中心");
            geRenZhongXin.setUrl("https://appigc72vmw2720.h5.xiaoeknow.com/homepage/30");

            Menu menu = new Menu();
            menu.setButton(Lists.newArrayList(woDeYiSheng,daYiZhiHui,geRenZhongXin));
            log.info("菜单信息：{}",String.valueOf(menu));
            weixinTemplate.menu().create(menu);
        } catch (Exception e) {
            return ResultMapper.error();
        }
        return ResultMapper.ok();
    }

    /*
    2021-01-28 日
     //【菜单一】 找名医
            SingleButton zhaomingyi = new SingleButton("找名医");
            ViewButton yishengliebiao = new ViewButton("医生列表");
            yishengliebiao.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb1a6ee9de43f2507&redirect_uri=https%3a%2f%2fweixin.dyzh120.com%2fdoctor%2flist&response_type=code&scope=snsapi_userinfo&state=DEFAULT&connect_redirect=1#wechat_redirect");
            ViewButton wodeyisheng = new ViewButton("我的医生");
            wodeyisheng.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb1a6ee9de43f2507&redirect_uri=https%3a%2f%2fweixin.api.dyzh120.com%2fauth%3furl%3dhttps%3a%2f%2fweixin.dyzh120.com%2fdoctors%3ftoken%3d&response_type=code&scope=snsapi_userinfo&state=DEFAULT&connect_redirect=1#wechat_redirect");
            zhaomingyi.setSubButton(Lists.newArrayList(yishengliebiao,wodeyisheng));


            //【菜单二】用好药
//            SingleButton yonghaoyao = new SingleButton("用好药");
//            ViewButton guanyuwomen = new ViewButton("关于我们");
//            guanyuwomen.setUrl("http://mp.weixin.qq.com/s?__biz=MzAxNjc2MDM4OA==&mid=509735582&idx=1&sn=5c880f4d5222d386ea3cbb14958c8ab9&chksm=007ab9b5370d30a32643893304c2efaabcb2356f5ed970bb7e53919d149afd28cb4a6a8b94b4#rd");
//            ViewButton guanyuhaoyao = new ViewButton("关于好药");
//            guanyuhaoyao.setUrl("http://mp.weixin.qq.com/s?__biz=MzAxNjc2MDM4OA==&mid=509735582&idx=2&sn=b332459d3b6b480d6129ca85006c0287&chksm=007ab9b5370d30a31f6c53a3a6041114c03aabed627b3712deafaa22ad2c4d85b40aad35cf87#rd");
//            yonghaoyao.setSubButton(Lists.newArrayList(guanyuwomen,guanyuhaoyao));
            //【菜单二】涨知识
            ViewButton zhangZhiShi = new ViewButton("涨知识");
            zhangZhiShi.setUrl("https://appigc72vmw2720.h5.xiaoeknow.com/");


            //【菜单三】旧版入口
            SingleButton jiubanrukou = new SingleButton("旧版入口");
            ViewButton jinrizhibo = new ViewButton("今日直播");
            jinrizhibo.setUrl("https://xcx.bjjk.com/wx/liveall/list");
            ViewButton yunduangongzuoshi = new ViewButton("云端工作室");
            yunduangongzuoshi.setUrl("https://xcx.bjjk.com/wx/studio_detail");
            ViewButton gerenguahao = new ViewButton("个人挂号");
            gerenguahao.setUrl("https://xcx.bjjk.com/wx/elist?from=singlemessage");
            ViewButton gerenzhongxin = new ViewButton("个人中心");
            gerenzhongxin.setUrl("https://xcx.bjjk.com/wx/personal_center");
            jiubanrukou.setSubButton(Lists.newArrayList(jinrizhibo,yunduangongzuoshi,gerenguahao,gerenzhongxin));

            Menu menu = new Menu();
            menu.setButton(Lists.newArrayList(zhaomingyi,zhangZhiShi,jiubanrukou));
            log.info("菜单信息：{}",String.valueOf(menu));
            weixinTemplate.menu().create(menu);
     */
}
